from django.db.models.fields.related import ForeignKey

import dmarkups.models
import dmarkups.forms

class MarkupField(ForeignKey):
    include_markups = None
    exclude_markups = None
    markup_choices = None
    
    def __init__(self, *args, **kwargs):
        kwargs['to'] = kwargs.get('to', dmarkups.models.Markup)
        self.include_markups = kwargs.get('include_markups', None)
        self.exclude_markups = kwargs.get('exclude_markups', None)
        self.markup_choices = kwargs.get('markup_choices', None)
        super(MarkupField, self).__init__(*args, **kwargs)

    def formfield(self, **kwargs):
        defaults = {'form_class': dmarkups.forms.MarkupField, 
                    'markup_model': self.rel.to,
                    'include_markups': self.include_markups,
                    'exclude_markups': self.exclude_markups,
                    'markup_choices': self.markup_choices}
        defaults.update(kwargs)
        return super(MarkupField, self).formfield(**defaults)